package com.wis.redis_test;

import com.wis.pool.redisCluster.MyJedisClusterPool;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;

import java.util.*;

/**
 * @Description: traffic_wis
 * @author: fan
 * @Date: Created in 2019/3/25 8:42
 * @Modified By:
 */
public class Redis_test {
    public static void main(String[] args) {
        String pattern = "110*201908131600*";// 1306521222019060307001411019
        List keys = new LinkedList();
        JedisCluster redisClusterObject = MyJedisClusterPool.getRedisClusterObject();
        Map<String, JedisPool> nodes = redisClusterObject.getClusterNodes();
        //遍历所有连接池，逐个进行模糊查询
        for (String k : nodes.keySet()) {
            JedisPool pool = nodes.get(k);
            System.out.println(pool);
            //获取Jedis对象，Jedis对象支持keys模糊查询
            Jedis connection = null;
            try {
                connection = pool.getResource();
                keys.addAll(connection.keys("*"));
                // Set<String> keys1 = connection.keys("*");
                // for (Object tmp : keys1) {
                //     String string = tmp.toString();
                //     if (string.length()<28&&string.contains("201904")){
                //         System.out.println(string);
                //         connection.del(string);
                //     }
                // }
                // keys.addAll(connection.keys(pattern));
            } catch (Exception e) {
                continue;
            } finally {
                //一定要关闭连接！
                if (connection!=null)
                connection.close();
            }
        }
        keys.forEach(System.out::println);
        System.out.println("-----------------------------");
        // String hget = redisClusterObject.hget("1114504812019052914200021519", "00");
        // String hget1 = redisClusterObject.hget("1114504812019052914200013138", "00");
        // System.out.println(redisClusterObject.exists("1114504812019052914200021519"));
        // System.out.println(hget);
        // System.out.println(hget1);
        // String get = redisClusterObject.get("351114504812019052914200021519");
        // System.out.println(get);
        // MyJedisClusterPool.returnJedisCluterObject(redisClusterObject);
    }

    @Test
    public void tsetRedis(){
        JedisCluster redisClusterObject = MyJedisClusterPool.getRedisClusterObject();
        Map<String, String> map = redisClusterObject.hgetAll("riskIndexRevision");
        System.out.println(map.toString());
    }

}
